Skip to content

add spam confidence #6660

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 14, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 32 additions & 10 deletions kitsune/llm/questions/prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@
- It contains QR codes or images containing external links.
- It is not relevant to Mozilla's "{product}" product.
# Specific instructions
# Instructions
Given a question, you must do the following:
- Determine whether or not the question is spam by considering each of the spam cases
listed above.
- Provide a reason for your determination.
- Provide your level of confidence in the determination as an integer from 0 to 100, with
0 representing the lowest confidence and 100 the highest.
# Response format instructions
{format_instructions}
Expand All @@ -48,9 +50,10 @@
{topics}
```
# Specific instructions
- Given a question, consider the title, description, and examples of each one of the
eligible topics listed above, and then select the most relevant topic.
# Instructions
Given a question, you must do the following:
- Consider the title, description, and examples (if provided) of each one of the eligible
topics listed above, and then select the most relevant topic.
- If you conclude that the question does not relate to Mozilla's "{product}" product,
or does not provide enough information to make a selection, select the "Undefined" topic.
- Provide a reason for your selection.
Expand All @@ -67,9 +70,18 @@
type="bool",
description="A boolean that when true indicates that the question is spam.",
),
ResponseSchema(
name="confidence",
type="int",
description=(
"An integer from 0 to 100 that indicates the level of confidence in the"
" determination of whether or not the question is spam, with 0 representing"
" the lowest confidence and 100 the highest."
),
),
ResponseSchema(
name="reason",
type="string",
type="str",
description="The reason for identifying the question as spam or not spam.",
),
)
Expand All @@ -80,19 +92,29 @@
(
ResponseSchema(
name="topic",
type="string",
description="The topic selected for the question.",
type="str",
description="The title of the topic selected for the question.",
),
ResponseSchema(
name="reason",
type="string",
type="str",
description="The reason for selecting the topic.",
),
)
)


spam_prompt = ChatPromptTemplate((("system", SPAM_INSTRUCTIONS), ("human", "{question}")))
spam_prompt = ChatPromptTemplate(
(
("system", SPAM_INSTRUCTIONS),
("human", "{question}"),
)
).partial(format_instructions=spam_parser.get_format_instructions())


topic_prompt = ChatPromptTemplate((("system", TOPIC_INSTRUCTIONS), ("human", "{question}")))
topic_prompt = ChatPromptTemplate(
(
("system", TOPIC_INSTRUCTIONS),
("human", "{question}"),
)
).partial(format_instructions=topic_parser.get_format_instructions())